﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.TaskEngine.EntityModel.Assignments;
using FluentNHibernate.Mapping;
using YasharEl.Infrastructure.TaskEngine.EntityModel;

namespace YasharEl.Infrastructure.TaskEngine.PersistenceModel.NHibernate.Assignments.Mappings
{
    public class TaskAssignmentEntityMap : ClassMap<TaskAssignmentEntity>
    {
        public TaskAssignmentEntityMap()
        {
            Table("TASK_ASSIGNMENTS");

            Id(x => x.TaskAssignmentId)
                .Column("ID")
                .GeneratedBy
                    .Identity();

            References(x => x.AssignedToTask)
                .Column("TASK_INSTANCE_ID")
                .LazyLoad()
                .Class<TaskEntity>();

            References(e => e.CreatedBy)
                .Column("CREATED_BY")
                .PropertyRef(u => u.UserIdentityId)
                .Not.Nullable()
                .Class<TaskParticipantEntity>();
            References(e => e.ModifiedBy)
                .Column("MODIFIED_BY")
                .PropertyRef(u => u.UserIdentityId)
                .Not.Nullable()
                .Class<TaskParticipantEntity>();

            References(x => x.AssignedTo)
                .Column("ASSIGNEE_ID")
                .PropertyRef(u => u.UserIdentityId)
                .LazyLoad()
                .Class<TaskParticipantEntity>();

            Map(x => x.CreatedDate)
                .Column("CREATED_DATE")
                .Not.Nullable();
            Map(x => x.ModifiedDate)
                .Column("MODIFIED_DATE")
                .Nullable();
        }
    }
}
